package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.FacadeNegocio;

import datatypes.LogoutDT;

//import java.awt.event.MouseAdapter;
//import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//import java.io.IOException;

public class PantallaInicial extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7125170344557724201L;
	public long getIdTerminal() {
		return idTerminal;
	}

	public void setIdTerminal(long idTerminal) {
		this.idTerminal = idTerminal;
	}

	private JPanel contentPane;
	private long idTerminal = 444;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PantallaInicial frame = new PantallaInicial();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PantallaInicial() {
		setTitle("TERMINAL");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
			
		JMenuItem mntmLogin = new JMenuItem("Login");
		mntmLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		menuBar.add(mntmLogin);
		
		JMenuItem mntmVenta = new JMenuItem("Venta");
		mntmVenta.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//FacadeNegocio FN = new FacadeNegocio();
				
				PantallaVenta pv = new PantallaVenta();
				pv.setVisible(true);

			}
		});
		menuBar.add(mntmVenta);
		
		JMenuItem mntmAnular = new JMenuItem("Anular");
		mntmAnular.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PantallaAnular pa = new PantallaAnular();
				pa.setVisible( true );
				
			}
		});
		menuBar.add(mntmAnular);
		
		JMenuItem mntmSalir = new JMenuItem("Salir");
		mntmSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
					try {
						
						System.out.println("SALIR");
						FacadeNegocio FN = FacadeNegocio.getInstance();
						LogoutDT logoutdt = new LogoutDT( 444 );
						FN.enviarObjeto( logoutdt );
						FN.cerrarConexion();
						//this.finalize();
						System.exit(0);
					} catch (Throwable e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		});
		menuBar.add(mntmSalir);
		
		this.setJMenuBar(getJMenuBar()); 
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}

}
